<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
<%@ include file="/common/common-css.v2.jsp"%>
<style>
#jquery-table td {
	cursor: pointer !important;
	word-break: break-all;
	word-wrap: break-word;
}

.load_bg {
	background: #000;
	opacity: 0.1;
	left: 0px;
	top: 0px;
	position: fixed;
	height: 100%;
	width: 100%;
	overflow: hidden;
	z-index: 10000;
}

.load_img {
	left: 50%;
	top: 180px;
	position: fixed;
	height: 50px;
	overflow: hidden;
	z-index: 20000;
}

a.check {
	margin-bottom: 10px;
}

@media ( min-width : 768px) and (max-width: 1200px) {
	.backup-text {
		width: 100px !important;
	}
}
</style>
</head>
<body class="no-skin">
	<div class="load_bg" style="display: none;"></div>
	<img src="http://img.tuanzidai.cn/commentloading.gif" class="load_img"
		style="display: none" />
	<div class="page-content">
		<div id="test"></div>
		<form id="queryForm">
			<div class="page-content-area">
				<div class="row">
					<div class="col-sm-12">
					    <input type="hidden" id="suffix" name="suffix">
						<div class="widget-box" style="border: 0px solid #ccc; border-top: none; border-bottom: none;">
							<div class="widget-header widget-header-blue widget-header-flat">
								<h4 class="widget-title">选择条件进行查询</h4>
								<div class="widget-toolbar">
									<a href="#" data-action="collapse"> <i
										class="ace-icon fa fa-chevron-up"></i>
									</a>
								</div>
							</div>

							<div class=" widget-body">
								<div class="widget-main" id="condition">
								    <div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label" style="text-align: right"
											for="sex">日期:</label>
										<div class="col-sm-8" style="padding-left: 0px">
										    <div class="input-daterange input-group">
												<input type="text" data-date-format="yyyy-mm-dd"
													class="date-picker input-sm form-control"
													style="padding-left: 0px" id="startTime" name="startTime"> 
												 <span class="input-group-addon" style="width: 6px"> 
												    <i class="fa fa-exchange"></i>
												 </span>
												 <input type="text" data-date-format="yyyy-mm-dd"
													class="date-picker input-sm form-control"
													style="padding-left: 0px" id="endTime" name="endTime">
											 </div>
										</div>
									</div>
									
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label" style="text-align: right">创建人:</label>
										<div class="col-sm-8" style="padding-left: 0;">
											<input type="text" name="operator" style="width: 100%; text-align: left;">
										</div>
									</div>
								
								    <div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right" for="isprize">日期格式:</label>
										<div class="col-sm-8" style="padding-left: 0;">
											<select class="form-control" id="dateformat" name="dateformat">
												<option value="0">日模式</option>
												<option value="1">周模式</option>
												<option value="2">月模式</option>
											</select>
										</div>
									</div>
									
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right" for="isprize">数据类型:</label>
										<div class="col-sm-8" style="padding-left: 0;">
											<select class="form-control" name="dataType">
												<option value="">全部</option>
												<option value="1">站内</option>
												<option value="2">短信</option>
												<option value="3">推广</option>
												<option value="4">公众号</option>
												<option value="5">外部联登</option>
											</select>
										</div>
									</div>
									
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label" 
										       style="text-align:right" >合作方:</label>
										 <div class="col-sm-8" style="padding-left: 0;">
											<select id="loan_product" name="sourceId" class="form-control">
											</select>
										</div>
									</div>
				
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right" for="isprize">产品</label>
										<div class="col-sm-8" style="padding-left: 0;">
											<select id="prdid" name="prdid" class="form-control"></select>
										</div>
									</div>
									
									<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label"
											style="text-align: right" for="isprize">数据来源:</label>
										<div class="col-sm-8" style="padding-left: 0;">
											<select class="form-control" id="source" name="source">
												<option value="1">正式</option>
												<option value="2">缓存</option>
											</select>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="col-md-12 center">
						<div class="clearfix form-actions myaction">
							<button class="btn btn-purple  no-border" type="button"
								name="btn-query" onclick="query_any()">
								<i class="ace-icon fa fa-search icon-on-right bigger-110"></i>
								查询
							</button>
							&nbsp;&nbsp;&nbsp;
							<button class="btn btn-grey no-border" type="reset">
								<i class="ace-icon fa fa-undo icon-on-right bigger-110"></i> 重置
							</button>
							&nbsp;&nbsp;&nbsp;
							<input id="upload_file" name="upload" type="file" style="display: none"/>
							<input id="upload_btn" type='button' class='btn' value='上传' />
							&nbsp;&nbsp;&nbsp;
							<button class="btn btn-grey no-border" type="button" onclick="confirmUpload()">
								<i class="ace-icon fa fa-undo icon-on-right bigger-110"></i> 确认
							</button>
						</div>
					</div>
				</div>
				
				<div class="row">
					<div class="col-xs-12">
					    <a href="javascript:void(0)" class="btn btn-success btn-small"
					      id="output" style="display: none;" onclick="loadlist()">导出列表</a>
						<table id="jquery-table"
							class="table table-striped table-bordered table-hover">
						</table>
					</div>
				</div>
			</div>
		</form>
	</div>
<%@ include file="/common/common-js.jsp"%>
<script type="text/javascript" src="${ctx}/js/call_func.js"></script>


<script type="text/javascript">

	function loadlist() {
		var form = document.forms["queryForm"];
		form.action = ctx + "/loanbusiness/exportData.action";
		form.submit();
	}
	
	
	//【查询】按钮Click事件
	function query_any() {
		$("#output").show();
		if (jqTable != null) {
			jqTable.fnDraw();
		} else {
			loaddata();
		}
	}

	var jqTable = null;
	var loaddata = function() {
		jQuery(function($) {
			jqTable = $('#jquery-table').dataTable(
					{
						//数据列控制（包括对应返回JSON属性名称，对应表头列索引位置、数据转换封装等）
						"columnDefs" : [
								{
									"title" : '日期',
									"targets" : [ 0 ],
									"data" : "csv_date",
									"class" : "center",
									"bSortable" : false,
									"width" : "50px",
								},
								{
									"title" : '创建人',
									"targets" : [ 1 ],
									"data" : "operator",
									"class" : "center",
									"bSortable" : false,
									"width" : "50px",
								},
								{
									"title" : '合作方ID',
									"targets" : [ 2 ],
									"data" : "source_id",
									"class" : "center",
									"bSortable" : false,
									"width" : "50px",
								},
								{
									"title" : '合作方名称',
									"targets" : [ 3 ],
									"data" : "activity_name",
									"class" : "center",
									"bSortable" : false,
									"width" : "50px",
									"render" : function(value, type, row) {
										if(value == null) {
											return "--";
										} else {
											return value;
										}
									}
								},
								{
									"title" : '所属类型',
									"targets" : [ 4 ],
									"data" : "type",
									"class" : "center",
									"bSortable" : false,
									"width" : "60px",
									"render" : function(value, type, row) {
										switch (row.type) {
										case 1:
											var temp = "站内";
											break;
										case 2:
											var temp = "短信";
											break;
										case 3:
											var temp = "推广";
											break;
										case 4:
											var temp = "公众号";
											break;
										case 5:
											var temp = "外部联登";
											break;
										default:
											var temp = "--";
											break;
										}
										return temp;
									}
								},
								{
									"title" : '产品',
									"name" : "prdid",
									"data" : "prdid",
									"targets" : [ 5 ],
									"bSortable" : false,
									"width" : "50px",
									"render" : function(value, type, row) { // 返回自定义内容
										switch (value) {
										case "8000":
											var temp = "菠萝贷主包";
											break;
										case "8001":
											var temp = "极速借钱";
											break;
										case "8002":
											var temp = "菠萝贷ios";
											break;
										case "8003":
											var temp = "手机现金侠";
											break;
										case "8004":
											var temp = "借了么";
											break;
										case "8005":
											var temp = "菠萝贷ios新";
											break;
										case "8006":
											var temp = "联登外部页";
											break;
										case "8100":
											var temp = "微信菠萝贷";
											break;
										case "8200":
											var temp = "香蕉还卡主包";
											break;
										case "8300":
											var temp = "速来贷";
											break;
										default:
											var temp = "--";
											break;
										}
										return temp;
									}
								},
								{
									"title" : '注册数',
									"targets" : [ 6 ],
									"data" : "register",
									"class" : "center",
									"bSortable" : false,
									"width" : "60px",
								},
								{
									"title" : '申请数',
									"targets" : [ 7 ],
									"data" : "apply",
									"class" : "center",
									"bSortable" : false,
									"width" : "60px",
								},
								{
									"title" : '进件成功数',
									"targets" : [ 8 ],
									"data" : "success",
									"class" : "center",
									"bSortable" : false,
									"width" : "50px",
								},
								{
									"title" : '出额数',
									"targets" : [ 9 ],
									"data" : "money_count",
									"class" : "center",
									"bSortable" : false,
									"width" : "50px",
									"render" : function(value, type, row) {
										if (value != null) {
											return value;
										} else {
											return "--";
										}
									}
								},
								{
									"title" : '总出额金额',
									"targets" : [ 10 ],
									"data" : "total_amount",
									"class" : "center",
									"bSortable" : false,
									"width" : "50px",
									"render" : function(value, type, row) {
										if (value != null) {
											return value;
										} else {
											return "--";
										}
									}
								},
								{
									"title" : '结算金额',
									"targets" : [ 11 ],
									"data" : "settle_amount",
									"class" : "center",
									"bSortable" : false,
									"width" : "50px",
									"render" : function(value, type, row) {
										if (value != null) {
											return value;
										} else {
											return "--";
										}
									}
								},
								{
									"title" : '件单价',
									"targets" : [ 12 ],
									"data" : "total_amount",
									"class" : "center",
									"bSortable" : false,
									"width" : "50px",
									"render" : function(value, type, row) {
										if (row.total_amount != null && row.money_count != null) {
											if(row.money_count == 0){
												return 0;
											}
											return (row.total_amount / row.money_count).toFixed(2);
										} else {
											return "--";
										}
									}
								},
								{
									"title" : '甲方放款成本',
									"targets" : [ 13 ],
									"data" : "settle_amount",
									"class" : "center",
									"bSortable" : false,
									"width" : "50px",
									"render" : function(value, type, row) {
										if (row.settle_amount != null && row.money_count != null) {
											if(row.money_count == 0){
												return 0;
											}
											return (row.settle_amount / row.money_count).toFixed(2);
										} else {
											return "--";
										}
									}
								}, ],
						"sAjaxSource" : ctx + "/loanbusiness/list.action?rand="
								+ Math.random(),//数据源URL
						"fnServerData" : function(sSource, aoData, fnCallback) {
							var data = $('#queryForm').serializeObject();
							data.aoData = JSON.stringify(aoData);
							$.ajax({
								"type" : "POST",
								"dataType" : 'json',
								"url" : sSource,
								"data" : data,
								"success" : function(resp) {
									fnCallback(resp);
									initListPage();
								},
								"error" : function(XMLHttpRequest, textStatus,
										errorThrown) {
								},
								"complete" : function() {
									$(".load_bg,.load_img").hide();
								}
							});
						},
						"fnRowCallback" : function(nRow, aData, iDisplayIndex,
								iDisplayIndexFull) {
							//=====================这里实现行双击事件======================//
						},
						"sScrollXInner" : "100%",
						"sScrollY" : "100%",//如果不设置，IE会有问题
						"aaSorting" : [ [ 0, "asc" ] ]
					//初始化加载，默认按第几列排序、排序方式（列从0开始计算）
					});
		 });
	}

	//时间控件
	jQuery(function($) {
		$(".date-picker").datepicker({
			autoclose : true
		}).next().on(ace.click_event, function() {
			$(this).prev().focus();
		});
	});

	$(document).ready(function() {
		loadProduct();
		queryLoanActivityList();
		$("#loan_product").combobox();
	});

	$('#upload_btn').click(function() {
		$('#upload_file').trigger('click');
	});

	$('#upload_file').change(
			
		function() {
			var filename = $("#upload_file").val();
			var extStart = filename.lastIndexOf(".");
			var ext = filename.substring(extStart + 1, filename.length)
					.toUpperCase();
	
			if ("XLSX" != ext && "XLS" != ext) {
				return alert("文件格式错误,请导入excel文件");
			}
	
			$("#suffix").val(ext);
			var form = new FormData(document.forms["queryForm"]);
	
			$.ajax({
				url : ctx + "/loanbusiness/upload.action",
				type : "post",
				data : form,
				processData : false,
				contentType : false,
				beforeSend : function() {
					showLoading();
				},
				success : function(data) {
					var total = JSON.parse(data).total;
					var success = JSON.parse(data).success;
					alert("TOTAL：" + total + "，SUCCESS：" + success);
					$("#source").val(2);
					$("#dateformat").val(0);
					query_any(); // 上传成功查询temp表
				},
				error : function(e) {
					alert("error");
				},
				complete : function(xhr, status) {
					hideLoading();
				}
			});
	});
	
	
	function confirmUpload(){
		$.ajax({
			url : ctx + "/loanbusiness/confirmUpload.action",
			type : "post",
			data : "",
			beforeSend : function() {
				showLoading();
			},
			success : function(data) {
				var total = JSON.parse(data).total;
				var success = JSON.parse(data).success;
				alert("TOTAL：" + total + "，SUCCESS：" + success);
				$("#source").val(1);
				query_any(0); // 上传成功查询
			},
			error : function(e) {
				alert("error");
			},
			complete : function(xhr, status) {
				hideLoading();
			}
		});
	}
	
	function showLoading() {
		$(".load_bg").show();
		$(".load_img").show();
	}

	function hideLoading() {
		$(".load_bg").hide();
		$(".load_img").hide();
	}
</script>
</body>
</html>